﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;
using System.IO;
using System.Text;

using CE.Image;
using CE.User;
using CE.Company;
using CE.Global;

public partial class controls_usrSubscribe : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            divSubscribe.Visible = true;
            divThankYou.Visible = false;
            txtEmail.Text = "";
        }
    }

    protected void ibtSubscribe_Click(object sender, EventArgs e)
    {
        ChangeValidationEffectServerSide("subscriber");
        if (Page.IsValid)
        {
            UserSubscriber _usersub = new UserSubscriber();
            UserSubscriberDB _usersubdb = new UserSubscriberDB();
            _usersub.Email = txtEmail.Text;
            if (_usersubdb.AlreadyExist(_usersub.Email) > 0)
            {
                divSubscribe.Visible = false;
                divThankYou.Visible = true;
                lblThankYou.Text = "";
                lblThankYou.Visible = false;
                lblExist.Visible = true;
            }
            else if (_usersubdb.Insert(_usersub) > 0)
            {
                divSubscribe.Visible = false;
                divThankYou.Visible = true;
                lblExist.Text = "";
                lblThankYou.Visible = true;
                lblExist.Visible = false;
            }
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        //Email
        if (rfvEmail.Enabled && rfvEmail.ValidationGroup == strValidationGroup)
        {
            rfvEmail.Validate();
            if (rfvEmail.IsValid == false)
            {
                txtEmail.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtEmail.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }

        if (revEmail.Enabled && revEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail.IsValid)
            {
                revEmail.Validate();
                if (revEmail.IsValid == false)
                {
                    txtEmail.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmail.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "";
        }
    }
}
